package cn.xcu;
import java.util.Scanner;
public class chap6 {
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            //读取学生总数
            int n = input.nextInt();
            //读取学生原始顺序
            int[] arr = new int[n];
            for (int i = 0;i < n; i++) {
                arr[i]=input.nextInt();
            }
            //读取调换次数
            int m = input.nextInt();
            for (int i = 0; i < m; i++){
                int x = input.nextInt()-1;
                int y = input.nextInt()-1;

                int temp = arr[x];
                arr[x] = arr[y];
                arr[y] = temp;

            }

            for (int ar : arr){
                System.out.print(ar);
                int i = 0;
                if(i<arr.length-1){
                    System.out.print(" ");
                }
            }
            System.out.println();
            input.close();
        }
}
